﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Data.SqlServerCe;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Controls
{
    public partial class InsertMusic_Control : UserControl
    {
        //Connection, should be passed in from containing class of component
        private SqlCeConnection mConnection = null;

        //Interface to set connection
        public SqlCeConnection Connection
        {
            set { mConnection = value; }
        }

        public InsertMusic_Control()
        {
            InitializeComponent();
        }

        private void insertButton_Click(object sender, EventArgs e)
        {
            if (songTextBox.Text.Length + artistTextBox.Text.Length + genreTextBox.Text.Length <= 0)
            {
                //empty, no insert
                MessageBox.Show("You must have text in at least one of the above boxes.");
            }
            else
            {
                String song = (songTextBox.Text.Length > 0 ? songTextBox.Text : null);
                String artist = (artistTextBox.Text.Length > 0 ? artistTextBox.Text : null);
                String genre = (genreTextBox.Text.Length > 0 ? genreTextBox.Text : null);
                String youtubelink = (youtubeTextBox.Text.Length > 0 ? youtubeTextBox.Text : null);

                SqlCeCommand insert;

                insert = new SqlCeCommand(String.Format("INSERT INTO Library (SongName, Artist, Genre, YouTubeLink) VALUES ('{0}', '{1}', '{2}', '{3}');", new Object[] { song, artist, genre, youtubelink }), mConnection );
                int mod = insert.ExecuteNonQuery();
                MessageBox.Show(String.Format("{0} Rows modified", mod));
            }
        }
     }
}